//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.kingyea.esb.platform;

import com.kingyea.esb.utils.jvm.JvmHelper;
import java.io.File;
import java.net.URL;

public class Main {
    private static Main daemon;

    public Main() {
    }

    public void init(String[] arguments) throws Exception {
        System.out.println("初始化服务...");
    }

    public static void start() throws Exception {
        String home = System.getProperty("KingyeaESBHome");
        if (home == null) {
            URL url = Main.class.getProtectionDomain().getCodeSource().getLocation();
            File file = new File(url.toURI());
            home = file.getParentFile().getParent();
            System.setProperty("KingyeaESBHome", home);
        }

        String pid = System.getProperty("Pid");
        if (pid == null) {
            System.setProperty("Pid", home + "/var/KingyeaESB.pid");
        }

        JvmHelper.writePid();
        Platform.getPlatform().start();
        System.out.println("成功启动，进程[" + JvmHelper.getPID() + "]");
    }

    public static void stop() throws Exception {
        System.exit(0);
        System.out.println("停止服务...");
    }

    public static void destroy() {
        System.out.println("销毁服务...");
    }

    public static synchronized void main(String[] args) {
        if (daemon == null) {
            Main bootstrap = new Main();

            try {
                bootstrap.init(args);
            } catch (Throwable var4) {
                var4.printStackTrace();
            }

            daemon = bootstrap;
        }

        try {
            String command = "start";
            if (args.length > 0) {
                command = args[args.length - 1];
                System.out.println("commands:" + command);
            }

            Main var10000;
            if (command.equals("start")) {
                var10000 = daemon;
                start();
            } else {
                var10000 = daemon;
                stop();
            }
        } catch (Throwable var3) {
            var3.printStackTrace();
        }

    }
}
